package com.xckj.teacher.ui.activity

import com.blankj.utilcode.util.ActivityUtils
import com.blankj.utilcode.util.ToastUtils
import com.xckj.teacher.R
import com.xckj.teacher.databinding.ActivityChangePassBinding
import com.xckj.teacher.framework.BaseActivity
import com.xckj.teacher.presenter.MinePresenter
import com.xckj.teacher.util.CacheUtil


class ChangePassActivity : BaseActivity<ActivityChangePassBinding>() {

    private val presenter: MinePresenter by lazy { MinePresenter(this) }

    override fun setStatusBarColor(): Int {
        return R.color.white
    }

    inner class ProxyClick {

        fun back() {
            finish()
        }

        fun reset() {
            var old = dataBinding?.etAccount?.text?.trim().toString()
            var new = dataBinding?.etPass?.text?.trim().toString()
            var newAgain = dataBinding?.etPassAgain?.text?.trim().toString()
            if (old.isNullOrEmpty() || new.isNullOrEmpty() || newAgain.isNullOrEmpty()) {
                ToastUtils.showShort("请输入密码")
                return
            }
            if (new != newAgain) {
                ToastUtils.showShort("请确认新密码两次输入一致")
                return
            }
            presenter.resetPass(old, new) {
                CacheUtil.setToken("")
                CacheUtil.setUser(null)
                ActivityUtils.finishAllActivities()
                ActivityUtils.startActivity(LoginActivity::class.java)
            }
        }


    }

    override fun loadLayout(): Int {
        return R.layout.activity_change_pass
    }

    override fun initData() {
        dataBinding.presenter = presenter
        dataBinding.click = ProxyClick()

    }

    override fun setListener() {

    }


    override fun isStatusBarDarkFont(): Boolean {
        return true
    }
}